package com.itboye.textileexpres.order;

import java.util.Observable;
import java.util.Observer;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.AdapterView.OnItemClickListener;

import com.itboye.textileexpes.beans.MyOrderBeans;
import com.itboye.textileexpes.presenter.MyOrderPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseFragment;
import com.itboye.textileexpres.base.MainApplication;
import com.itboye.textileexpres.base.ResultEntity;
import com.itboye.textileexpres.base.WebActivity;
import com.itboye.textileexpres.util.ClickListener;
import com.itboye.textileexpres.util.IsMobileNumPhone;
import com.itboye.textileexpres.widget.XListView;
import com.itboye.textileexpres.widget.XListView.IXListViewListener;
/**
 * 
 * @author 待收货
 *
 */
public class FragmentOrderWanchengGood extends BaseFragment implements Observer ,ClickListener,IXListViewListener{
	int i;
	XListView mylist;
	WanChengGoodAdapter adapter;
	MyOrderPresenter myOrderPresenter;
	MyOrderBeans beans;
	int page_size=1;
	int page_index=10;
	private LinearLayout linearyoutIsnull;
	public FragmentOrderWanchengGood(int i) {
		this.i = i;
	}

	@Override
	public int initView() {
		
		return R.layout.fragment_myorder;
	}

	@Override
	public void onMyActivityCreated() {
//		 订单搜索MyOrderShaerActivity
		myOrderPresenter = new MyOrderPresenter(this);
		beans = new MyOrderBeans();

		
		beans.setUid(IsMobileNumPhone.isUid());
		beans.setQuery_status("7");
		page_size++;
		myOrderPresenter.getInfo(beans);
		
		
		mylist.setPullLoadEnable(true);
		mylist.setPullRefreshEnable(true);
		mylist.setXListViewListener(this);
	}

	@Override
	public void update(Observable observable, Object data) {
		
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == myOrderPresenter.Fenye_success) {
				beans = (MyOrderBeans) entity.getData();
				if (beans.getList().size() <= 0) {
					linearyoutIsnull.setVisibility(View.VISIBLE);
					mylist.setVisibility(View.GONE);
				} else if (beans.getList() == null) {
					linearyoutIsnull.setVisibility(View.VISIBLE);
					mylist.setVisibility(View.GONE);
				} else {
				adapter = new WanChengGoodAdapter(getActivity(), beans,this);
				mylist.setAdapter(adapter);
				try {
					closeProgressDialog();
				} catch (Exception e) {
					// TODO: handle exception
				}
				onIsStop();
				}
			}else if(entity.getEventType()==myOrderPresenter.Fenye_fail){
				onIsStop();
			}
		}
	}

	@Override
	public void onWuliu(View v) {
		
		Intent intent = new Intent(MainApplication.context, WebActivity.class);
		intent.putExtra("url",
				"http://api.guannan.itboye.com/public/web.php/Express/index?order_code="
						+ beans.getList().get((Integer)v.getTag()).getOrder_code() + "39"
						+ IsMobileNumPhone.isPasswrd());
		intent.putExtra("title", "物流查看");
		startActivity(intent);
	}

	@Override
	public void onBtnSend(View v) {
		
		
	}

	@Override
	public void onCle(View v) {
		
		
	}

	@Override
	public void onOkConfirm(View v) {
		
	}
	@Override
	public void onRefresh() {
		// TODO Auto-generated method stub
		showProgressDialog("数据加载中...", true);
		beans.setUid(IsMobileNumPhone.isUid());
		page_size = 1;
		beans.setQuery_status("7");
		myOrderPresenter.getInfo(beans);
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		beans.setUid(IsMobileNumPhone.isUid());
		beans.setQuery_status("7");
		page_size++;
		myOrderPresenter.getInfo(beans);
	}
	public  void  onIsStop(){
		mylist.stopRefresh();
		mylist.stopLoadMore();
	}
}
